home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13206 < prev    next >
Encoding:
Text File  |  1996-08-05  |  960 b   |  37 lines

  1. Path: news.luc.edu!user
  2. From: VArase@varase.it.luc.edu (Verne Arase)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Date: Thu, 04 Apr 1996 21:30:55 -0600
  6. Organization: LUMC
  7. Message-ID: <AD89F00F96681642B@mcdiala09.it.luc.edu>
  8. References: <31616F63.481D@lava.weeg.uiowa.edu>
  9. NNTP-Posting-Host: 147.126.240.109
  10.  
  11. In article <31616F63.481D@lava.weeg.uiowa.edu>,
  12. Artur Wojdat <awojdat@lava.weeg.uiowa.edu> wrote:
  13.  
  14.  >    Is there a function or some sort of way that I could remove '\n' 
  15.  >charecter form the end of the string. I'm reading from two files, want to
  16.  
  17.  >form one line of text and then have it printed out to stdout. I use fgets
  18. to 
  19.  >read from the file and I noticed that it appends newline char at the end.
  20.  
  21. Try:
  22.  
  23.    int  len;
  24.    char *endptr;
  25.  
  26.    ...
  27.  
  28.    if ((len=strlen(buf))>0) {
  29.       endptr=buf+len;
  30.       if (*--endptr=='\n')
  31.          *endptr=0;
  32.       }
  33.  
  34.  
  35. ---
  36. The above are my own opinions, and not those of my employer.
  37.